package cn.xiezonjie.action;


import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.omg.CORBA.Request;

import cn.xiezonjie.dao.MenuDao;
import cn.xiezonjie.model.Menu;

import com.opensymphony.xwork2.ActionSupport;


@SuppressWarnings("serial")
public class MenuPageAction extends ActionSupport{

	ArrayList<Menu> list;
	Menu menu;
	
	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public ArrayList<Menu> getList() {
		return list;
	}

	public String search() throws SQLException, ParseException{
    
    	MenuDao dao=new MenuDao();
    	list =dao.Search();
		
    	return "search";
    	
    }


	public String query() throws SQLException, ParseException{
		HttpServletRequest request=ServletActionContext.getRequest();
		String type=request.getParameter("Type");
		String key=request.getParameter("Key");
		
		MenuDao dao=new MenuDao();
		
		list =dao.query(type, key);
		if(list==null||list.size()<=0)
		{
			return "no";
		}else{
		     return "query";
		}
	
	}
	
	public String delete() throws SQLException{
		MenuDao dao=new MenuDao();
		HttpServletRequest request=ServletActionContext.getRequest();
		
		String m_id=request.getParameter("m_id");
		int a = Integer.parseInt(m_id);
		dao.delete(a);
        return "delete";
	}

	
	public String SearchById() throws SQLException{
		MenuDao dao=new MenuDao();
		
		
		HttpServletRequest request=ServletActionContext.getRequest();
		
		String m_id=request.getParameter("m_id");
		int a = Integer.parseInt(m_id);
		menu=dao.SearchById(a);
		
		
        return "searchbyid";
	}
	
	
	public String updata()
	{   HttpServletRequest request=ServletActionContext.getRequest();
		MenuDao dao=new MenuDao();
	    
	   
		String m_id=request.getParameter("idd");
		int a = Integer.parseInt(m_id);
		menu.setM_id(a);
		System.out.println(m_id);
	    dao.Update(menu);
	
    return "Update";
		 
		
	}
	
	
	
	
	
	public String query_order() throws SQLException, ParseException{
		HttpServletRequest request=ServletActionContext.getRequest();
		String type=request.getParameter("Type");
		String key=request.getParameter("Key");
		System.out.println("查询菜品时的类型和关键字为 : "+type+"  "+key);
		
		MenuDao dao=new MenuDao();
		
		list =dao.query(type, key);
		if(list==null||list.size()<=0)
			return "no";
		
		return "query_order";
	
	
	}
	
	

}
